package com.fusheng.springcloud.service;

import com.fusheng.springcloud.pojo.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 服务降级
 */

@Component
public class DeptClientServiceFallbackFactory implements FallbackFactory {

    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService() {
            @Override
            public Dept quertById(Long id) {
                return new Dept()
                        .setDeptno(id)
                        .setDname("id = >"+id+" 没有这个数据，客户端提供了降级信息，这个服务被关闭咯")
                        .setDb_source("no data in mysql");
            }

            @Override
            public List<Dept> queryAll() {
                ArrayList<Dept> depts = new ArrayList<>();
                depts.add(new Dept());
                return depts;
            }

            @Override
            public Boolean addDept(Dept dept) {
                return false;
            }
        };
    }
}
